package myky.com.doctorapp.presenter

import io.reactivex.disposables.Disposable
import myky.com.doctorapp.R
import myky.com.doctorapp.base.BasePresenterIm
import myky.com.doctorapp.base.RxSubscribe
import myky.com.doctorapp.contract.RemoteDetailsActivityContract
import myky.com.doctorapp.entity.RemoteDetailsEntity
import myky.com.doctorapp.entity.RemoteRepeatEntity
import myky.com.doctorapp.entity.RemoteSupplyEntity
import myky.com.doctorapp.model.RemoteDetailsActivityModel
import myky.com.doctorapp.utils.ToastUtils

/**
 * Description:
 *
 * @author wuyangwuyang
 * Created by 2019/3/11 on 16:09
 */
class RemoteDetailsActivityPresenter : BasePresenterIm<RemoteDetailsActivityContract.View>(),RemoteDetailsActivityContract.Presenter {


    var remoteDetailsActivityModel:RemoteDetailsActivityModel= RemoteDetailsActivityModel()
    override fun premoteDetail(remoteId: String) {
        remoteDetailsActivityModel.remoteDetail(remoteId).subscribe(object :RxSubscribe<RemoteDetailsEntity.PayLoadBean>(){
            override fun onSuccess(t: RemoteDetailsEntity.PayLoadBean) {
                mView.showContentView()
                mView.showDataSuccess(t)
            }

            override fun onFailed(code: Int, msg: String?) {
                mView.showNetErrorView()
            }

            override fun onSubscribe(d: Disposable) {
                mView.showLoadingView()
                addSubscription(d)
            }

        })
    }

    override fun pcancelResult(remoteId: String) {
        remoteDetailsActivityModel.remoteCancel(remoteId).subscribe(object :RxSubscribe<RemoteRepeatEntity.PayLoadBean>(){
            override fun onSuccess(t: RemoteRepeatEntity.PayLoadBean) {
                mView.showContentView()
                mView.cancelResult(t)
            }

            override fun onFailed(code: Int, msg: String?) {
                ToastUtils.show(mContext.resources.getString(R.string.net_exception))
            }

            override fun onSubscribe(d: Disposable) {
                mView.showLoadingView(mContext.resources.getString(R.string.remote_cancel))
                addSubscription(d)
            }

        })
    }

    override fun premoteSupply(remoteId: String,remoteSupplyEntity: RemoteSupplyEntity) {

        remoteDetailsActivityModel.remoteSupply(remoteId,remoteSupplyEntity).subscribe(object :RxSubscribe<RemoteRepeatEntity.PayLoadBean>(){
            override fun onSuccess(t: RemoteRepeatEntity.PayLoadBean) {
                mView.showContentView()
                mView.suppltyResult(t)
            }

            override fun onFailed(code: Int, msg: String?) {
                ToastUtils.show(mContext.resources.getString(R.string.net_exception))
            }

            override fun onSubscribe(d: Disposable) {
                mView.showLoadingView(mContext.resources.getString(R.string.RemoteSubmit_loading))
                addSubscription(d)
            }

        })
    }
}
